/*
 * @Author: wenqingwu 18417432@qq.com
 * @Date: 2023-07-11 09:06:28
 * @LastEditors: wenqingwu 18417432@qq.com
 * @LastEditTime: 2023-07-11 14:50:48
 * @FilePath: \w325coding-react\day104\router-v5\src\login\LoginView.jsx
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import React, { useState } from 'react';
import { Prompt } from 'react-router-dom';
import Auth from './../util/AuthMock'
import { Redirect } from 'react-router-dom/cjs/react-router-dom.min';
const LoginView = (props) => {
  console.log(props)
  const [redirectState, setRedirectState] = useState(false)
  const login = () => {
    // fetch(), 调用接口，成功后。。。。。
    Auth.aututhenticate(() => {
      // 1. 直接跳转：location.state.from.pathname
      // props.history.push(props.location.state.from.pathname)

      // 2. 改状态
      setRedirectState(true)
    });
  }

  if (redirectState) {
    return (<Redirect to={props.location.state.from} />)
  }
  return (
    <div>
      <h1>Login View</h1>
      {/* <button type='button' onClick={login}>登录</button> */}
      <button type='button' onClick={() => {
        props.history.push("/home")
      }}>登录</button>
    </div>
  );
}

export default LoginView;
